/*
 * Anteil der richtigen Vorhersagen für Wörter
 *   -> Spalte 1 durch Spalte 3
 */
package complet.app.tool.experiment;

import complet.helper.IOHelper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Comparator;
import java.util.TreeMap;

public class experiment2 {

    private static BufferedReader ws1 = IOHelper.openReadFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\1111_250T\\WordStat_1.log");
    private static BufferedReader ws2 = IOHelper.openReadFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\1111_250T\\WordStat_2.log");
    private static BufferedReader ws3 = IOHelper.openReadFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\1111_250T\\WordStat_3.log");
    private static TreeMap<String, Integer> tm1_1 = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm2_1 = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm3_1 = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm1_3 = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm2_3 = new TreeMap<String, Integer>();
    private static TreeMap<String, Integer> tm3_3 = new TreeMap<String, Integer>();
    private static TreeMap<String, Double> tm1_o = new TreeMap<String, Double>();
    private static TreeMap<String, Double> tm2_o = new TreeMap<String, Double>();
    private static TreeMap<String, Double> tm3_o = new TreeMap<String, Double>();
    private static TreeMap<String, Double> tm1_so = null;
    private static TreeMap<String, Double> tm2_so = null;
    private static TreeMap<String, Double> tm3_so = null;
    private static BufferedWriter out1 = IOHelper.openWriteFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\1111_250T\\WordStat_1.ex2");
    private static BufferedWriter out2 = IOHelper.openWriteFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\1111_250T\\WordStat_2.ex2");
    private static BufferedWriter out3 = IOHelper.openWriteFile("E:\\paul\\Dokumente\\MyDocuments\\NetBeans Workspace\\Completion\\stats\\1111_250T\\WordStat_3.ex2");
    private static final Comparator<String> COMP_1 = new Comparator<String>() {

        public int compare(String s1, String s2) {
            if (tm1_o.get(s1) > tm1_o.get(s2)) {
                return -1;
            }
            if (tm1_o.get(s1) < tm1_o.get(s2)) {
                return 1;
            }
            if (tm1_1.get(s1) > tm1_1.get(s2)) {
                return -1;
            }
            if (tm1_1.get(s1) < tm1_1.get(s2)) {
                return 1;
            }
            if (tm1_3.get(s1) > tm1_3.get(s2)) {
                return -1;
            }
            if (tm1_3.get(s1) < tm1_3.get(s2)) {
                return 1;
            }
            return 1;
        }
    };
    private static final Comparator<String> COMP_2 = new Comparator<String>() {

        public int compare(String s1, String s2) {
            if (tm2_o.get(s1) > tm2_o.get(s2)) {
                return -1;
            }
            if (tm2_o.get(s1) < tm2_o.get(s2)) {
                return 1;
            }
            if (tm2_1.get(s1) > tm2_1.get(s2)) {
                return -1;
            }
            if (tm2_1.get(s1) < tm2_1.get(s2)) {
                return 1;
            }
            if (tm2_3.get(s1) > tm2_3.get(s2)) {
                return -1;
            }
            if (tm2_3.get(s1) < tm2_3.get(s2)) {
                return 1;
            }
            return 1;
        }
    };
    private static final Comparator<String> COMP_3 = new Comparator<String>() {

        public int compare(String s1, String s2) {
            if (tm3_o.get(s1) > tm3_o.get(s2)) {
                return -1;
            }
            if (tm3_o.get(s1) < tm3_o.get(s2)) {
                return 1;
            }
            if (tm3_1.get(s1) > tm3_1.get(s2)) {
                return -1;
            }
            if (tm3_1.get(s1) < tm3_1.get(s2)) {
                return 1;
            }
            if (tm3_3.get(s1) > tm3_3.get(s2)) {
                return -1;
            }
            if (tm3_3.get(s1) < tm3_3.get(s2)) {
                return 1;
            }
            return 1;
        }
    };

    public static void main(String[] args) {
        tm1_so = new TreeMap<String, Double>(COMP_1);
        tm2_so = new TreeMap<String, Double>(COMP_2);
        tm3_so = new TreeMap<String, Double>(COMP_3);

        try {
            String strLine;
            String line[];
            // Für WordStat1
            while (true && (strLine = ws1.readLine()) != null) {
                line = strLine.split("\t");
                tm1_1.put(line[0], Integer.parseInt(line[1]));
                tm1_3.put(line[0], Integer.parseInt(line[3]));
            }
            // Für WordStat2
            while (true && (strLine = ws2.readLine()) != null) {
                line = strLine.split("\t");
                tm2_1.put(line[0], Integer.parseInt(line[1]));
                tm2_3.put(line[0], Integer.parseInt(line[3]));
            }
            // Für WordStat3
            while (true && (strLine = ws3.readLine()) != null) {
                line = strLine.split("\t");
                tm3_1.put(line[0], Integer.parseInt(line[1]));
                tm3_3.put(line[0], Integer.parseInt(line[3]));
            }
        } catch (IOException ex) {
            IOHelper.logError("(experiment1) Failed to read input file: " + ex.getMessage());
        }


        // WordStat1
        for (String key : tm1_1.keySet()) {
            tm1_o.put(key, ((double) tm1_1.get(key)) / tm1_3.get(key));
        }
        // WordStat2
        for (String key : tm2_1.keySet()) {
            tm2_o.put(key, ((double) tm2_1.get(key)) / tm2_3.get(key));
        }
        // WordStat3
        for (String key : tm3_1.keySet()) {
            tm3_o.put(key, ((double) tm3_1.get(key)) / tm3_3.get(key));
        }

        tm1_so.putAll(tm1_o);
        tm2_so.putAll(tm2_o);
        tm3_so.putAll(tm3_o);
        try {
            out1.write("### Anteil an Volltreffer pro Wort ###\n");
            out1.write("### Wort <TAB> Anteil(Quotient) <TAB> Anzahl Treffer <Tab> Anzahl Vorkommen ###\n");
            for (String key : tm1_so.keySet()) {
                out1.write(key + "    " + tm1_o.get(key) + "    " + tm1_1.get(key) + "    " + tm1_3.get(key) + "\n");
            }
            out1.close();

            out2.write("### Anteil an Volltreffer pro Wort ###\n");
            out2.write("### Wort <TAB> Anteil(Quotient) <TAB> Anzahl Treffer <Tab> Anzahl Vorkommen ###\n");
            for (String key : tm2_so.keySet()) {
                out2.write(key + "    " + tm2_o.get(key) + "    " + tm2_1.get(key) + "    " + tm2_3.get(key) + "\n");
            }
            out2.close();

            out3.write("### Anteil an Volltreffer pro Wort ###\n");
            out3.write("### Wort <TAB> Anteil(Quotient) <TAB> Anzahl Treffer <Tab> Anzahl Vorkommen ###\n");
            for (String key : tm3_so.keySet()) {
                out3.write(key + "    " + tm3_o.get(key) + "    " + tm3_1.get(key) + "    " + tm3_3.get(key) + "\n");
            }
            out3.close();
        } catch (IOException ex) {
            IOHelper.logError("(experiment1) Failed to write result file: " + ex.getMessage());
        }
    }
}
